﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using Telerik.Web.UI;
using KPIS.Utils;
using KPIS.GERP.GHRMS.MODEL;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class PR_BudgetManagements : System.Web.UI.Page
    {
        private BudgetManagementTestBLL BLL = new BudgetManagementTestBLL();
        private IEmployeeTypeBLL etBLL = new EmployeeTypeBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindEmpType();
                bindYearCombo();
                LoadDataGrid();
            }
        }
        private void bindEmpType()
        {
            IList<EmployeeTypeInfo> infoList = etBLL.ListEmployeeTypes();

            cmbEmployeeType.DataSource = infoList;
            cmbEmployeeType.DataBind();
            cmbEmployeeType.SelectedIndex = 0;
        }
        public void bindYearCombo()
        {
            int curYear = int.Parse(DateTime.Today.Year.ToString());
            curYear += 543;
            int MinYear = curYear - 10;
            int MaxYear = curYear + 10;
            DataTable dt = new DataTable();
            DataColumn dc = dt.Columns.Add("Name");

            for (int i = MinYear; i <= MaxYear; i++)
            {
                dt.Rows.Add(Convert.ToString(i));
            }
            cmbFilterYear.DataSource = dt;
            cmbFilterYear.DataBind();
            cmbFilterYear.SelectedValue = curYear.ToString();
            cmbYear_SelectedIndexChanged(null, null);
        }
        private void LoadDataGrid()
        {
            try
            {
                int nYear = cmbFilterYear.SelectedValue.Length > 0 ? Int32.Parse(cmbFilterYear.SelectedValue) : 0;
                int nPromotion = radPromotion.SelectedValue.Length > 0 ? Int32.Parse(radPromotion.SelectedValue) : 0;
                int nEmpType = cmbEmployeeType.SelectedValue.Length > 0 ? Int32.Parse(cmbEmployeeType.SelectedValue) : 0;

                DataTable jobsite = BLL.Management(nYear, nPromotion, nEmpType);
                RadGrid2.DataSource = jobsite;
                RadGrid2.DataBind();
            }
            catch (Exception ex)
            {
                Web.ShowAlert(this, ex.Message);
            }
        }

        protected void cmbYear_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            LoadDataGrid();
        }

        protected void radPromotion_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadDataGrid();
        }


        protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e)
        {
            Session["EmpTypeSeq"] = 1;
            Session["BGYear"] = cmbFilterYear.SelectedValue;
            Session["Period"] = radPromotion.SelectedValue;
            LoadDataGrid();
        }

        protected void cbEmployeeType_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            LoadDataGrid();
        }
    }
}
